package service;

public class merch {
    public int guangpan;
    public int xiangyan;
    public int huazhuang;
    public int wanju;
    public int shouji;
    public int jiajiu;
    public int av;
    public int qiche;
    public int guwan;
    public int fangzi;
    public String msg1;
    public String msg2;


    public merch(){
        ran();
    }

    public void ran(){
        String[] news = {"盗版光碟涨价","进口香烟涨价","劣质化妆品涨价","进口玩具降价","水货手机涨价","剧毒假酒涨价","东京热涨价","走私汽车涨价","古玩涨价","商品房降价"};
        int count = 4 + (int)(7 * Math.random());
        if(count == 11){
            count = 10;
        }
        init();
        while(count > 0){
            if(add((int)(10 * Math.random()))){
                count--;
            }
        }
        int i = 0,j;
        if(Math.random() > 0.5){
            i = (int)(10 * Math.random());
            while(check(i)){
                i = (int)(10 * Math.random());
            }
            if(i == 10){
                i = 9;
            }
            this.msg1 = news[i];
            buff(i);
        }
        if(Math.random() > 0.5){
            j = (int)(10 * Math.random());
            while(check(j) || j == i){
                j = (int)(10 * Math.random());
            }
            if(j == 10){
                j = 9;
            }
            this.msg2 = news[j];
            buff(j);
        }
    }

    public void init(){
        this.guangpan = 0;
        this.xiangyan = 0;
        this.huazhuang = 0;
        this.wanju = 0;
        this.shouji = 0;
        this.jiajiu = 0;
        this.av = 0;
        this.qiche = 0;
        this.guwan = 0;
        this.fangzi = 0;
        this.msg1 = "";
        this.msg2 = "";
    }

    public void buff(int i){
        if(i == 0) {
            this.guangpan *= 2;
        }
        else if(i == 1) {
            this.xiangyan *= 2;
        }
        else if(i == 2) {
            this.huazhuang *= 2;
        }
        else if(i == 3) {
            this.wanju /= 2;
        }
        else if(i == 4) {
            this.shouji *= 2;
        }
        else if(i == 5) {
            this.jiajiu *= 2;
        }
        else if(i == 6) {
            this.av *= 2;
        }
        else if(i == 7) {
            this.qiche *= 2;
        }
        else if(i == 8) {
            this.guwan *= 2;
        }
        else if(i == 9) {
            this.fangzi /= 2;
        }
    }

    public boolean check(int i){
        if(i == 0){
            if(guangpan == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 1){
            if(xiangyan == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 2){
            if(huazhuang == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 3){
            if(wanju == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 4){
            if(shouji == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 5){
            if(jiajiu == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 6){
            if(av == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 7){
            if(qiche == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 8){
            if(guwan == 0){
                return true;
            }
            else{
                return false;
            }
        }
        else{
            if(fangzi == 0){
                return true;
            }
            else{
                return false;
            }
        }
    }

    public boolean add(int i){
        if(i == 0){
            if(guangpan == 0){
                guangpan = (int)(5 + 45 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 1){
            if(xiangyan == 0){
                xiangyan = (int)(100 + 300 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 2){
            if(huazhuang == 0){
                huazhuang = (int)(100 + 300 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 3){
            if(wanju == 0){
                wanju = (int)(200 + 800 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 4){
            if(shouji == 0){
                shouji = (int)(600 + 900 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 5){
            if(jiajiu == 0){
                jiajiu = (int)(800 + 1200 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 6){
            if(av == 0){
                av = (int)(5000 + 8000 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 7){
            if(qiche == 0){
                qiche = (int)(15000 + 15000 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else if(i == 8){
            if(guwan == 0){
                guwan = (int)(30000 + 60000 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
        else{
            if(fangzi == 0){
                fangzi = (int)(1000000 + 1000000 * Math.random());
                return true;
            }
            else{
                return false;
            }
        }
    }
}
